/*
 * @Author: 何丽彬
 * @Email: helibin@yingzi.com
 * @Date: 2021-11-19 09:14:15
 * @LastEditTime: 2021-11-26 14:12:19
 * @LastEditors: 何丽彬
 * @FilePath: \process-learn\多进程\thread.js
 */
// 主线程 thread.js
console.time("timer");

const { Worker, isMainThread } = require("worker_threads");
const cpuNum = require("os").cpus().length;

let cnt = cpuNum;
for (let i = 0; i < cpuNum; i++) {
  const worker = new Worker("./thread_child.js");
  worker.postMessage("start");
  worker.on("message", () => {
    if (--cnt === 0) {
      console.timeEnd("timer");
      process.exit(0);
    }
  });
}
